package pl.edu.mimuw.mas.ontology;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import pl.edu.mimuw.mas.ontology.concept.Color;
import pl.edu.mimuw.mas.ontology.concept.LogEntry;
import pl.edu.mimuw.mas.ontology.concept.Point;
import pl.edu.mimuw.mas.ontology.concept.Position;
import jade.content.onto.BasicOntology;
import jade.content.onto.Ontology;
import jade.content.schema.ConceptSchema;
import jade.content.schema.PredicateSchema;
import jade.content.schema.PrimitiveSchema;

/**
 * Ontologia wykorzystywana podczas próśb o zwizualizowanie agenta.
 */
public final class VisualizationCoreOntology extends Ontology {
	private static final long serialVersionUID = 1726054707491083627L;

	public static final String ONTOLOGY_NAME = "viz-core-ontology";
	
	private static final String POINT = "Point";
	private static final String POINT_X = "x";
	private static final String POINT_Y = "y";
	private static final String POINT_Z = "z";
	
	private static final String COLOR = "Color";
	private static final String COLOR_R = "r";
	private static final String COLOR_G = "g";
	private static final String COLOR_B = "b";
	
	private static final String POSSITION = "Possition";
	private static final String POSSITION_AGENT_ID = "agentId";
	private static final String POSSITION_POINT = "point";
	private static final String POSSITION_COLOR = "color";
	private static final String POSSITION_EVENT_DATE = "eventDate";

	private static final String LOG_ENTRY = "LogEntry";
	private static final String LOG_ENTRY_AGENT_ID = "agentId";
	private static final String LOG_ENTRY_VALUE = "value";
	private static final String LOG_ENTRY_DATE = "date";
	
	private static Ontology instance = new VisualizationCoreOntology();

	public static Ontology getInstance() {
		return instance;
	}

	private Logger logger = LoggerFactory.getLogger(getClass());
	
	private VisualizationCoreOntology() {
		super(ONTOLOGY_NAME, BasicOntology.getInstance());
		
		try {
			add(new ConceptSchema(POINT), Point.class);
			add(new ConceptSchema(COLOR), Color.class);
			add(new PredicateSchema(POSSITION), Position.class);
			add(new ConceptSchema(LOG_ENTRY), LogEntry.class);
			
			ConceptSchema cs = (ConceptSchema) getSchema(POINT);
			cs.add(POINT_X, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
			cs.add(POINT_Y, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
			cs.add(POINT_Z, (PrimitiveSchema) getSchema(BasicOntology.FLOAT));

			cs = (ConceptSchema) getSchema(COLOR);
			cs.add(COLOR_R, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
			cs.add(COLOR_G, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
			cs.add(COLOR_B, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));

			PredicateSchema ps = (PredicateSchema) getSchema(POSSITION);
			ps.add(POSSITION_AGENT_ID, (PrimitiveSchema) getSchema(BasicOntology.STRING));
			ps.add(POSSITION_POINT, (ConceptSchema) getSchema(POINT));
			ps.add(POSSITION_COLOR, (ConceptSchema) getSchema(COLOR));
			ps.add(POSSITION_EVENT_DATE, (PrimitiveSchema) getSchema(BasicOntology.DATE));
			

			cs = (ConceptSchema) getSchema(LOG_ENTRY);
			cs.add(LOG_ENTRY_AGENT_ID, (PrimitiveSchema) getSchema(BasicOntology.STRING));
			cs.add(LOG_ENTRY_VALUE, (PrimitiveSchema) getSchema(BasicOntology.STRING));
			cs.add(LOG_ENTRY_DATE, (PrimitiveSchema) getSchema(BasicOntology.DATE));
		} catch (Exception e) {
			logger.error("Niemożna utworzyć ontologii {}", getClass().getName(), e);
		}
	}
}
